package orm

import (
	"gluenet/pkg/ops/dbi"
)

const (
	_resourceMap = `select update_time,resource_tree from resource_tree where root="glue"
`
	_resourceDag = `select update_time,instances_dag from resource_dag where root=?
`
)

func ResourceMap(c dbi.GlueDB, data interface{}) error {
	//var res = []struct {
	//	UpdateTime string `json:"update_time" yaml:"update_time"`
	//	ResourceTree string `json:"resource_tree" yaml:"resource_tree"`
	//}{}
	if err := c.MetaDB().SQL(_resourceMap).Find(data); err != nil {
		return err
	}
	return nil
}

func ResourceDag(c dbi.GlueDB, root string, data interface{}) error {
	//var res = []struct {
	//	UpdateTime string `json:"update_time" yaml:"update_time"`
	//	ResourceTree string `json:"resource_tree" yaml:"resource_tree"`
	//}{}
	if err := c.MetaDB().SQL(_resourceDag, root).Find(data); err != nil {
		return err
	}
	//c.Logger.Debugf("get data %v", data)
	return nil
}
